﻿using System.Web.Script.Serialization;
using BLL.Access;
using Common;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;

namespace Web.ashx
{
    /// <summary>
    /// EditDaiChuLi 的摘要说明
    /// </summary>
    public class EditDaiChuLi : IHttpHandler
    {
        
        public void ProcessRequest(HttpContext context)
        {
           
            string type = context.Request["type"];
            if(type== "show")
            {
                string lx = context.Request["lx"];
                string bh = context.Request["bh"];
                List <EditDaiChuLiCX > list= showData(Convert.ToInt32(lx), bh);
                JavaScriptSerializer jesr = new JavaScriptSerializer();
                string listjson = jesr.Serialize(list);
                context.Response.Write(listjson);
            }
            else if (type == "Edit")
            {
                SpHelper sh = new SpHelper();
                string err="";
                string id = context.Request["id"].ToString();
                string laihanbh= context.Request["laihanbh"].ToString();
                int i_m1 = Convert.ToInt32(context.Request["i_m1"].ToString());
                int i_m2 = Convert.ToInt32(context.Request["i_m2"].ToString());
                int i_m3 = Convert.ToInt32(context.Request["i_m3"].ToString());
                int i_m4 = Convert.ToInt32(context.Request["i_m4"].ToString());
                int i_m5 = Convert.ToInt32(context.Request["i_m5"].ToString());
                int i_m6 = Convert.ToInt32(context.Request["i_m6"].ToString());
                int i_m7 = Convert.ToInt32(context.Request["i_m7"].ToString());
                int i_m8 = Convert.ToInt32(context.Request["i_m8"].ToString());
                int i_m9 = Convert.ToInt32(context.Request["i_m9"].ToString());
                int i_m10 = Convert.ToInt32(context.Request["i_m10"].ToString());
                int i_m11 = Convert.ToInt32(context.Request["i_m11"].ToString());
                int i_m12 = Convert.ToInt32(context.Request["i_m12"].ToString());
                sh.YS_XG_EDITDAICHULIXG(id, laihanbh, i_m1, i_m2, i_m3, i_m4, i_m5, i_m6, i_m7, i_m8, i_m9, i_m10, i_m11, i_m12, out err);
                context.Response.Write(err);
            }
        }
        public static List<EditDaiChuLiCX> showData(int lx,string bh)
        {
            SpHelper sh = new SpHelper();
            DataSet ds= sh.P_YSLH_GETFENHUXX(lx, bh);
            List<EditDaiChuLiCX> list = new List<EditDaiChuLiCX>();
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                EditDaiChuLiCX model = new EditDaiChuLiCX();
                model.S_YONGHUH = ds.Tables[0].Rows[i]["S_YONGHUH"].ToString();
                model.S_YONGHUM = ds.Tables[0].Rows[i]["S_YONGHUM"].ToString();
                model.IM_1 = ds.Tables[0].Rows[i]["I_M1"].ToString();
                model.IM_2 = ds.Tables[0].Rows[i]["I_M2"].ToString();
                model.IM_3 = ds.Tables[0].Rows[i]["I_M3"].ToString();
                model.IM_4 = ds.Tables[0].Rows[i]["I_M4"].ToString();
                model.IM_5 = ds.Tables[0].Rows[i]["I_M5"].ToString();
                model.IM_6 = ds.Tables[0].Rows[i]["I_M6"].ToString();
                model.IM_7 = ds.Tables[0].Rows[i]["I_M7"].ToString();
                model.IM_8 = ds.Tables[0].Rows[i]["I_M8"].ToString();
                model.IM_9 = ds.Tables[0].Rows[i]["I_M9"].ToString();
                model.IM_10 = ds.Tables[0].Rows[i]["I_M10"].ToString();
                model.IM_11 = ds.Tables[0].Rows[i]["I_M11"].ToString();
                model.IM_12 = ds.Tables[0].Rows[i]["I_M12"].ToString();
                model.IM_13 = ds.Tables[0].Rows[i]["I_M13"].ToString();
                list.Add(model);
            }
            return list;
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}